<?php
class goodsList extends Activity {
    function indexTask(){
        $result=array();
        View::displayAsHtml($result, "goods-list.php");
    }

    function searchTask($text,$orderBy,$asc,$page){
        $goods=GoodsMode::init();
        $asc = $asc==1?true:false;
        if(!empty($orderBy)){
            $r[$orderBy]=$asc;
        }
        // 现有的参数
        $r['paramRemain']=array('text'=>$text);
        $page=empty($page)||$page<0 ? 1:(int)$page;
        $countOfPage=16;
        $offset=($page-1)*$countOfPage;
        list($r['goods'],$total)=GoodsMode::init()->getList(null,null,null,$text,$orderBy,$asc,$countOfPage,$offset);
        if($total!=0 && !empty($r['goods'])){
            $r['list']=$goods->getDetailInfo($r['goods']);
            $goods->sortGoods($r['list'], $orderBy, $asc);
        }else{
            $r['list']=array();
        }
        $url=WebRouter::init()->getQuestion("page=");
        $r['page']=new Page($page,$total,$countOfPage);
        $r['page']->setPageCallback(function($page)use($url,$text,$orderBy,$asc){
            return $url.$page."&text=".$text."&orderBy=".$orderBy."&asc=".$asc;
        });
        $r['category']=MenuModule::init()->getAll(0);
        usort($r['category'],function($a,$b){
            return -$a['point']+$b['point'];
        });
        $r['pageTitle']=TextFilter::htmlCut($text,0);
        $r['is_bottom']=false;
        $r['pageEmpty']=$total==0?true:false;
        View::displayAsHtml($r, "goods-list.php");
    }
}